<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SmartMad Monitor</title>
<link rel="stylesheet" href="../assets/css/bootstrap-spacelab.css" />
<link rel="stylesheet" href="../assets/css/base.css?t=20130516173114" />

  <!-- template
    ================================================== -->
    <script id="t_a" type="text/html">
        <table class="table table-striped table-bordered table-condensed">
            <thead>
                <tr>
                    <th>用户名</th>
                    <th>真实名字</th>
                    <th>Email</th>
                    <th>用户描述</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <% 
					for (var i in json) { var item = json[i];
				 %>
                <tr>
					<td>
						<%= i %>
					</td>                	
                    <td>
                       <div><%= item[0] ? item[0] : '' %></div>
                    </td>
                    <td>
                       <div><%= item[1] ? item[1] : '' %></div>
                    </td>
                    <td>
                    	<div><%= item[2] ? item[2] : '' %></div>
                    </td>
                    <td>
                    	<% if(item[3] != 0) { %>
						<button class="btn" name="modify" data-name="<%= i %>">
							<i class="icon-edit" title="修改"></i>
						</button>
							&nbsp;&nbsp;&nbsp;
							<button class="btn" name="delete" data-name="<%= i %>">
								<i class="icon-trash" title="删除"></i>
							</button>
						<% } %>
                    </td>
                </tr>
                <% } %>
            </tbody>
        </table>
    </script>
	
</head>
<body>
    <header>
        <h1>用户管理</h1>
        <div id="toolbar">
        	<div class="box_1">
        		<button class="btn" id="add"><i class="icon-plus-sign"></i> 添加用户</button>
        	</div>  
        </div> 
    </header>	


    <div id="mainbody">
        <div id="users">
        </div>
    </div>

  <!-- js part
    ================================================== -->
<script src="../assets/js/library/jquery-1.7.1.js"></script>
<script src="../assets/js/library/bootstrap.min.js"></script>
<script src="../assets/js/library/template.js"></script>
<script src="../assets/js/helper.js?t=20130516173114"></script>
<script src="../assets/js/doc.js?t=20130516173114"></script>	
<script>
$(function(){
	
    var smartMad = window.smartMad = window.smartMad || {};
	
    var getUserAllConf = {
        url: smartMad._url + smartMad.api.getUserAll
    };
	
    var getUserAllCall = function(e, json){
    
        var $th = $(this), data, html;
        
        //$th.html(JSON.stringify(json));return;
        ///////////////////////////////////////////////
        
        data = {
            json: json
        };
        
        /////////////////////////////////////////////
        
        html = template('t_a', data);
        $th.html(html);
		
    };
	

    ///////////////////////////////////////////////////////////	
	//init
	///////////////////////////////////////////////////////////
	var $users = $('#users');
    
    $users.bind('ajax.success', getUserAllCall).getData(getUserAllConf);
	
    ///////////////////////////////////////////////////////////
	//event bind
	///////////////////////////////////////////////////////////
    $('body')
	.delegate('#add','click',function(){
        location.href = 'editUser.html?version=' + smartMad.version;
    })
	.delegate('button[name="modify"]','click',function(){
        var name = $(this).attr('data-name');
        location.href = 'editUser.html?name=' + name + '&version=' + smartMad.version;
    })
    .delegate('button[name="delete"]','click',function(){
        var name = $(this).attr('data-name');
        var conf = {
			type:'get',
            url: smartMad._url + smartMad.api.delUser + name,
            success: function(json, textStatus, jqXHR){
                $.tips('已经删除!');
                this.parent().parent().remove();
            }
        };
        if (confirm('确定删除！')) {
            $(this).delData(conf);
        }
    });
	
	///////////////////////////////////////////////////////////
    
});
</script>
</body>
</html>
